﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Isha.Infrastructure;
using Isha.Entities;
using System.Web.Mvc;
using Isha.Web.Mvc;

namespace Isha.Extensions.Page
{
    [Command(typeof(Page))]
    public class PageCommand : IContentCommand
    {       
        public void Execute()
        {
            if (IshaContext.Current.Request.FormCollection != null && (IshaContext.Current.Command == Commands.Create || IshaContext.Current.Command == Commands.Edit))
            {
                ContentItem contentItem = IshaContext.Current.ContentItem;

                contentItem.ContentXml = IshaContext.Current.Serializer(contentItem.Type, new Page()
                                            {
                                                BodyText = IshaContext.Current.Request.FormCollection["Page_BodyText"]
                                            });

                IshaContext.Current.ContentItem = contentItem;
            }
        }
    }
}
